package com.gaoshi.chapter4;

public class StaticTest {
    public static void main(String[] args) {
        EmployeeStatic[] staff = new EmployeeStatic[3];

        staff[0] = new EmployeeStatic("Tom", 40000);
        staff[1] = new EmployeeStatic("Dick", 60000);
        staff[2] = new EmployeeStatic("Harry", 65000);

        for (EmployeeStatic e : staff) {
            e.setId();
            System.out.println(e);
        }

        int nextId = EmployeeStatic.getNextId();
        System.out.println("Next available id=" + nextId);
    }
}

class EmployeeStatic {
    private static int nextId = 1;

    private final String name;
    private final double salary;
    private int id;

    public EmployeeStatic(String n, double s) {
        name = n;
        salary = s;
    }

    public static int getNextId() {
        return nextId;
    }

    public static void main(String[] args) {
        EmployeeStatic harry = new EmployeeStatic("harry", 5000);
        System.out.println(harry.getName() + " " + harry.getSalary());
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public int getId() {
        return id;
    }

    public void setId() {
        id = nextId;
        nextId++;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", id=" + id +
                '}';
    }
}